#include "mymodel.h"

MyModel::MyModel(QObject *parent) :
    QAbstractListModel(parent)
{
    m_strings << "first" << "second" << "third";
}

QVariant MyModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()){
        return QVariant();
    }

    if (role == Qt::EditRole ||
            role == Qt::DisplayRole){
        return m_strings[index.row()];
    }

    return QVariant();
}

bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    if (!index.isValid()){
        return false;
    }

    if (role == Qt::EditRole || role == Qt::DisplayRole){
        m_strings[index.row()] = value.toString();
        emit dataChanged(index, index);
        return true;
    }

    return false;
}

Qt::ItemFlags MyModel::flags(const QModelIndex &index) const
{
    if (!index.isValid()){
        return Qt::ItemIsEnabled;
    }

    return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
}

int MyModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return m_strings.count();
}
